package com.prs.crm.action.crm;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.context.AppContext;
import com.prs.crm.domain.crm.CustomerSales;
import com.prs.crm.service.crm.CustomerSalesService;

public class CustomerSalesAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	
	private PaginationSupport pagination;
	private CustomerSales customerSales;
	private CustomerSalesService customerSalesService;
	private Integer[] salesIds;
	
	@Action("listCustomerSales")
	public String listCustomerSupplier(){
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				CustomerSales.class);
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.customerSalesService.listByPage(criteria,
				pagination));
		return SUCCESS;
	}
	@Action("editCustomerSales")
	public String editCustomerSales(){
		if(this.salesIds!=null){
			this.customerSales=this.customerSalesService.get(salesIds[0]);
		}
		return SUCCESS;
	}
	@Action(value = "saveCustomerSales", results = {
			@Result(name = "success", type = "redirect", location = "listCustomerSales"),
			@Result(name = "error", type = "chain", location = "editCustomerSales") })
	public String saveCustomerSales() {
		if(customerSales.getId()==null){
			this.customerSalesService.save(customerSales);
		}else{
			this.customerSalesService.submit(customerSales);
		}
		return SUCCESS;
	}
	@Action(value = "removeCustomerSales", results = {
			@Result(name = "success", type = "redirect", location = "listCustomerSales"),
			@Result(name = "error", type = "chain", location = "listCustomerSales") })
	public String removeCustomerSales() {
		this.customerSalesService.batchRemove(salesIds);
		return SUCCESS;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public CustomerSales getCustomerSales() {
		return customerSales;
	}
	public void setCustomerSales(CustomerSales customerSales) {
		this.customerSales = customerSales;
	}
	public CustomerSalesService getCustomerSalesService() {
		return customerSalesService;
	}
	public void setCustomerSalesService(CustomerSalesService customerSalesService) {
		this.customerSalesService = customerSalesService;
	}

	public Integer[] getSalesIds() {
		return salesIds;
	}

	public void setSalesIds(Integer[] salesIds) {
		this.salesIds = salesIds;
	}
	
}
